package com.learn.springbootcache.controller;

import com.learn.springbootcache.bean.Org;
import com.learn.springbootcache.mapper.OrgMapper;
import com.learn.springbootcache.service.OrgService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrgContrlller {

    private static final Logger logger = LoggerFactory.getLogger(OrgContrlller.class);

    @Autowired
    OrgService orgService;

    @GetMapping("/org/{id}")
    public Org getOrgById(@PathVariable Integer id) {
        Org org = orgService.getOrgById(id);
        if (org == null) {
            logger.info("查询部门信息不存在，部门ID：{}", id);
            return null;
        }
        logger.info("查询到部门信息：{}", org.toString());
        return org;
    }

    @GetMapping("/updateOrg")
    public Integer updateOrg(Org org){
        int upOrgNum = orgService.updateOrg(org);
        logger.debug("更新了{}条信息", upOrgNum);
        return upOrgNum;
    }

    @GetMapping("/delOrg/{id}")
    public Integer delOrg(Integer id){
        int delOrgNum = orgService.delOrg(id);
        logger.debug("删除了org表中{}条数据", delOrgNum);
        return delOrgNum;
    }

}
